<template>
	<view class="content">
		<downloadPop  :file_path="file_path"></downloadPop>
		<mescroll-uni ref="mescrollRef" @init="mescrollInit"  @up="upCallback" :up="upOption" :down="{use: false}">
			<view class="section-0">
			<view class="section-body">
				<view class="form">
					<view class="form-item">
						<view class="label">文件名</view>
						<view class="shape"></view>
						<view class="input">
							<u--input
								placeholderClass="input-placeholder"
								class="input-body"
							    v-model="form.fileName"
							  ></u--input>
						</view>
					</view>
					<view class="form-time">
						<view class="label">发文时间</view>
						<view class="wrapper">
							<view @click="setCurTime(item)" :class="`item ${curTime.id === item.id ? 'item__active' : ''}`" v-for="item in timeList" :key="item.id">
								{{item.name}}
							</view>
						</view>
					</view>
					<view class="form-item">
						<view class="label">关键字</view>
						<view class="shape"></view>
						<view class="input">
							<u--input
								placeholderClass="input-placeholder"
								class="input-body"
							    v-model="form.keyWord"
							  ></u--input>
						</view>
					</view>
					<view class="form-item">
						<view class="label">发文单位</view>
						<view class="shape"></view>
						<view class="input">
							<u--input
								placeholderClass="input-placeholder"
								class="input-body"
							    v-model="form.operName"
							  ></u--input>
						</view>
					</view>
					<view class="actions">
						<view class="action" @click="handleResetForm">
							<text>重</text>
							<text>置</text>
						</view>
						<view class="action search" @click="handleSearch">
							<text>查</text>
							<text>询</text>
						</view>
					</view>
				</view>
				<view class="list">
					<view class="item" v-for="item in list" :key="item.id">
						<view class="left">
							<view class="name">
								{{item.wj_name}}
							</view>
							<view class="info">
								<text>{{item.oper_name}}</text>
								<text>发布年份：{{item.fw_time}}</text>
							</view>
						</view>
						<view class="action" @click="handleDownLoad(item.file_path)">
							<view class="iconfont icon-xiazai"></view>
							<!-- <view class="down-count">
								{{item.useCount}}次
							</view> -->
						</view>
					</view>
				</view>
			</view>
		</view>
		</mescroll-uni>
	</view>
</template>

<script>
	import { ruleListApi } from '@/api/statistics.js';
	import { mapGetters, mapActions} from 'vuex';
	import downloadPop from '@/components/download_pop/index.vue';
	export default {
		components: { downloadPop },
		data() {
			return {
				mescroll: null, // mescroll实例对象 (此行可删,mixins已默认)
				upOption:{
					textNoMore: '-- 没有更多了 --'
				},
				pageSize:20,
				board: [
					{ name: '项目总数', count: 34, right: true },
					{ name: '完成项目总数', count: 34, right: true },
					{ name: '未完成项目总数', count: 34 },
				],
				curTime: {},
				timeList: [
					{id: 1, name: '2020以前', value: "< 2020"},
					{id: 2, name: '2020', value: '= 2020'},
					{id: 3, name: '2021', value: '= 2021'},
					{id: 4, name: '2022', value: '= 2022'},
				],
				list: [],
				form: {
					type: '发文',
					fwTime: '',
					fileName: '',
					keyWord: '',
					operName: ''
				},
				pageSize: 20,
				file_path: ''
			};
		},
		// onLoad(data) {
		// 	this.form.type = data.type;
		// 	if(this.form.type == '技术标准'){
		// 		this.form.type = '发文'
		// 	}
		// 	uni.setNavigationBarTitle({
		// 		title: data.type
		// 	});
		// },
		methods: {
			handleDownLoad(url) {
				this.file_path = '';
				setTimeout(() => {
					this.file_path = url;
				}, 0);
			},
			setCurTime(item) {
				this.curTime = item;
				this.form.fwTime = item.value;
			},
			mescrollInit(mescroll) {
				this.mescroll = mescroll;
			},
			/*上拉加载的回调*/
			async upCallback(page) {
				const {data} =  await ruleListApi({
					...this.form,
					page: page.num,
					pageSize: this.pageSize
				});
				// debugger
				if (data.code === 1 || data.code === 200) {
					// 接口返回的当前页数据列表 (数组)
					let curPageData = data.data.data; 
					// 接口返回的当前页数据长度 (如列表有26个数据,当前页返回8个,则curPageLen=8)
					let curPageLen = curPageData.length; 
					// 接口返回的总页数 (如列表有26个数据,每页10条,共3页; 则totalPage=3)
					let totalPage = data.data.last_page; 
					//设置列表数据
					if(page.num == 1) this.list = []; //如果是第一页需手动置空列表
					this.list = this.list.concat(curPageData); //追加新数据
					// 请求成功,隐藏加载状态
					this.mescroll.endByPage(curPageLen, totalPage); 
					setTimeout(()=>{
						this.mescroll.endSuccess(curPageLen);
					},20);
				} else{
					//  请求失败,隐藏加载状态
					this.mescroll.endErr()
				}
			},
			handleResetForm(){
				this.form.fwTime=''
				this.form.fileName=''
				this.form.keyWord=''
				this.form.operName=''
				this.curTime = ''
				this.mescroll.resetUpScroll();
				this.mescroll.scrollTo(0,0);
			},
			handleSearch(){
				this.mescroll.resetUpScroll();
				this.mescroll.scrollTo(0,0);
			},
		},
	}
</script>

<style lang="scss" scoped>
	.content{
		background-color: #3a5df5;
	}
	.section-0{
		z-index: 10;
		background-color: #2e5efe;
		.section-body{
			width: 100%;
			height: 100%;
			border-top-left-radius: 50rpx;
			border-top-right-radius: 50rpx;
			background-color: #fff;
			overflow: hidden;
		.list{
			width: 670rpx;
			box-sizing: border-box;
			margin-left: 40rpx;
			border-top: 2rpx solid #d8e4f2;
			.item{
				box-sizing: border-box;
				width: 100%;
				padding: 20rpx 40rpx 15rpx 40rpx;
				border-bottom: solid 2rpx #f2f2f0;
				@include clear();
				.left{
					float: left;
					width: 520rpx;
					.info{
						width: 100%;
						float: left;
						line-height: 24prx;
						font-size: 16rpx;
						color: #7f98ae;
						text{
							margin-bottom: 5rpx;
							display: block;
							min-width: 100%;
							&:last-child{
								margin-right: 0;
							}
						}
					}
					.name{
						width: 520rpx;
						padding: 5rpx 0;
						font-size: 26rpx;
						font-weight: normal;
						font-stretch: normal;
						line-height: 30rpx;
						letter-spacing: 2rpx;
						color: #3b3c40;
						float: left;
					}
				}
				.action{
					float: right;
					width: 32rpx;
					text-align: center;
					color: #3b3c40;
					.iconfont{
						display: inline-block;
						height: 40rpx;
						line-height: 40rpx;
						font-size: 32rpx;
						transition: 0.2s ease;
					}
					.down-count{
						width: 100%;
						height: 24rpx;
						line-height: 24prx;
						font-size: 16rpx;
						color: #7f98ae;
						white-space: nowrap;
					}					
				}
			}
		}
		.actions{
			width: 100%;
			height: 50rpx;
			margin-top: 29rpx;
			padding-bottom: 40rpx;
			display: flex;
			justify-content: space-between;
			.action{
				width: 288rpx;
				height: 48rpx;
				background-color: #395cf5;
				border-radius: 20rpx;
				text-align: center;
				line-height: 48rpx;
				font-size: 26rpx;
				font-weight: normal;
				font-stretch: normal;
				color: #ffffff;
				text{
					&:first-child{
						margin-right: 20rpx;
					}
				}
			}
			.search{
				background-color: #1534ce;
			}
		}
		.form{
			width: 100%;
			padding: 0 75rpx;
			padding-top: 40rpx;
			box-sizing: border-box;
			.form-time{
				width: 600rpx;
				min-height: 48rpx;
				margin: 0 auto;
				margin-bottom: 9rpx;
				@include clear;
				.label{
					float: left;
					width: 134rpx;
					height: 48rpx;
					text-align: center;
					line-height: 44rpx;
					font-size: 26rpx;
					font-weight: normal;
					font-stretch: normal;
					letter-spacing: 0rpx;
					color: #1534ce;
				}
				.wrapper{
					float: left;
					width: calc(100% - 134rpx);
					line-height: 48rpx;
					.item{
						float: left;
						display: inline-block;
						height: 48rpx;
						border-radius: 35rpx;
						padding: 0 20rpx;
						background-color: #395cf5;
						text-align: center;
						font-size: 26rpx;
						line-height: 48rpx;
						color: #fff;
						margin-left: 10rpx;
						transition: 0.3s ease;
						margin-bottom: 16rpx;
					}
					.item__active{
						background-color: #1534ce;
					}
				}
			}
			.form-item{
				width: 600rpx;
				height: 48rpx;
				border-radius: 20rpx;
				border: solid 2rpx #1534ce;
				margin: 0 auto;
				margin-bottom: 25rpx;
				&:last-child{
					margin-bottom: 34rpx;
				}
				@include clear();
				.label{
					float: left;
					width: 134rpx;
					height: 48rpx;
					text-align: center;
					line-height: 44rpx;
					font-size: 26rpx;
					font-weight: normal;
					font-stretch: normal;
					letter-spacing: 0rpx;
					color: #1534ce;
				}
				.shape{
					width: 3rpx;
					height: 32rpx;
					background-color: #7f98ae;
					float: left;
					margin-top: 8rpx;
				}
				.input{
					float: left;
					width: calc(100% - 134rpx - 3rpx);
					.input-body{
						box-sizing: border-box;
						width: 100%;
						height: 44rpx;
						padding: 0!important;
						border: none;
						padding-left: 30rpx!important;
						padding-right: 30rpx!important;
						font-size: 26rpx;
						font-weight: normal;
						font-stretch: normal;
						letter-spacing: 0rpx;
						color: rgba(0,0,0,0.7);
					}
					.input-placeholder{
						font-size: 26rpx;
						font-weight: normal;
						font-stretch: normal;
						letter-spacing: 0rpx;
						color: rgba(0,0,0,0.5);
					}
				}	
			}
		}
		}
	}
</style>
